package com.bbs.toutiao.mapper.clinet;

import com.bbs.toutiao.vo.article.ArticlePageRequestVo;
import com.bbs.toutiao.vo.article.ArticleVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface ClientArticleEditMapper {
    //新增文章
    @Insert("insert into t_articles (article_title,class_id,create_user_id,img,article_text,data_category) values (#{articleTitle},#{classId},#{createUserId},#{img},#{article_text},#{dataCategory})")
    int insertArticle(ArticleVo articleVo);

    //资讯浏览，分类查询，搜索查询文章
    List<ArticleVo> dynamicQueryArticle(ArticlePageRequestVo requestVo);

    //统计资讯浏览，分类查询，搜索查询的文章查询总数
    long  dynamicQueryArticleCount(ArticlePageRequestVo requestVo);

    //根据用户id分页查询文章
    List<ArticleVo>  queryArticleByUserId(ArticlePageRequestVo requestVo);


    //客户端根据评论id列表查询文章
    List<ArticleVo> articleListByCommentsUserId(List<Integer> commentIds,int userId);

    //根据用户id查询获取文章总数
    @Select("select count(*) from t_articles where  create_user_id=#{createUserId} AND status = 0")
    long articlesCount(int createUserId);

    //用户关注的id查询被关注者发布的信息
    List<ArticleVo> articlesFollowsUserId(List<Integer> listId,int page,int size,int userId);

    //统计被关注用户发布文章的总数
    long countByFollowsUserId(List<Integer> listId);


    //查询用户收藏数量
    @Select("select count(*) from t_favorites where  user_id=#{userId}")
    long favoritesCount(int userId);

    //通过收藏文章id查询收藏列表
    List<ArticleVo> articleByFavoritesArticleId(List<Integer> integers,int page,int size,int userId);

    //删除文章404
    @Update("update t_articles set status=404    WHERE id=#{articleId} AND create_user_id=#{userId}")
    int deleteArticle(int articleId,int userId);


    //搜索用户
    List<ArticleVo> queryUserPage(int page,int size,String userName,int userId);

    long countQueryUser(String userName);
}
